package leetcode.greed;

//nums = [2,3,1,1,4]
//[2,3,0,1,4]
//[3,2,1]
//[10,9,8,7,6,5,4,3,2,1,1,0]
public class Test45 {
    public static void main(String[] args) {
        int nums[] = {3};
        System.out.println(jump(nums));
    }

    public static int jump(int[] nums) {
        if (nums.length == 1) {
            return 0;
        }
        int index = 0;
        int count = 0;
        while (index < nums.length) {
            int max = nums[index + 1]+index+1;
            int end = nums[index] + index;
            if (end>=nums.length-1){
                count++;
                break;
            }
            for (int i = index + 1; i <= end; i++) {
                if (nums[i]+i >= max) {
                    max = nums[i]+i;
                    index = i;
                }
            }
            count++;
        }
        return count;
    }
}
